from django_redis import get_redis_connection


class RedisTool:
    def __init__(self):
        self.redis = get_redis_connection('code')

    def set_code(self, phone, code):
        self.redis.setex(phone,7200, code)

    def get_code(self, phone):
        code = self.redis.get(phone)
        if not code:
            return None
        return code.decode('utf-8')


redistool = RedisTool()
